home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / DOSTOP.C < prev    next >
C/C++ Source or Header  |  1992-05-05  |  6KB  |  192 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/dos386/microcode/RCS/dostop.c,v 1.1 1992/05/05 06:55:13 jinx Exp $
  4.  
  5. Copyright (c) 1992 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. #include "msdos.h"
  36. #include "dostop.h"
  37. #include "osctty.h"
  38. #include "dosutil.h"
  39. #include "errors.h"
  40. #include "option.h"
  41.  
  42. extern void EXFUN (DOS_initialize_channels, (void));
  43. extern void EXFUN (DOS_initialize_ctty, (int interactive));
  44. extern void EXFUN (DOS_initialize_directory_reader, (void));
  45. extern void EXFUN (DOS_initialize_environment, (void));
  46. extern void EXFUN (DOS_initialize_processes, (void));
  47. extern void EXFUN (DOS_initialize_signals, (void));
  48. extern void EXFUN (DOS_initialize_terminals, (void));
  49. extern void EXFUN (DOS_initialize_trap_recovery, (void));
  50. extern void EXFUN (DOS_initialize_conio, (void));
  51. extern void EXFUN (DOS_initialize_tty, (void));
  52. extern void EXFUN (DOS_initialize_userio, (void));
  53.  
  54. extern void EXFUN (DOS_reset_channels, (void));
  55. extern void EXFUN (DOS_reset_processes, (void));
  56. extern void EXFUN (DOS_reset_terminals, (void));
  57. extern void EXFUN (execute_reload_cleanups, (void));
  58.  
  59. extern void EXFUN (DOS_ctty_save_external_state, (void));
  60. extern void EXFUN (DOS_ctty_save_internal_state, (void));
  61. extern void EXFUN (DOS_ctty_restore_internal_state, (void));
  62. extern void EXFUN (DOS_ctty_restore_external_state, (void));
  63.  
  64. /* reset_interruptable_extent */
  65.  
  66. extern CONST char * OS_Name;
  67. extern CONST char * OS_Variant;
  68.  
  69. static int interactive;
  70.  
  71. int
  72. DEFUN_VOID (OS_under_emacs_p)
  73. {
  74.   return (option_emacs_subprocess);
  75. }
  76.  
  77. void
  78. DEFUN_VOID (OS_initialize)
  79. {
  80.   dstack_initialize ();
  81.   transaction_initialize ();
  82.   interactive = 1;
  83.   
  84.   DOS_initialize_channels ();
  85.   DOS_initialize_environment ();
  86.   DOS_initialize_tty ();
  87.   DOS_initialize_trap_recovery ();
  88.   DOS_initialize_signals ();
  89.   DOS_initialize_directory_reader ();
  90.   DOS_initialize_conio();
  91.   OS_Name = SYSTEM_NAME;
  92.   OS_Variant = SYSTEM_VARIANT;
  93.  
  94.   { version_t version_number;
  95.  
  96.     dos_get_version(&version_number);
  97.     fprintf (stdout, "MIT Scheme running under %s %d.%d 386/486\n",
  98.              OS_Variant,
  99.              (int) version_number.major, (int) version_number.minor);
  100.     /* To make our compiler vendors happy. */           
  101.     fprintf(stdout,
  102.         "Copyright (c) 1990, 1991, 1992 Massachusetts Institute of Technology\n");
  103.   }
  104.  
  105.   fputs ("", stdout);
  106.   fflush (stdout);
  107. }
  108.  
  109. void
  110. DEFUN_VOID (OS_reset)
  111. {
  112.   /*
  113.     There should really be a reset for each initialize above,
  114.     but the rest seem innocuous.
  115.    */
  116.  
  117.   DOS_reset_channels ();
  118.   execute_reload_cleanups ();
  119. }
  120.  
  121. void
  122. DEFUN (OS_quit, (code, abnormal_p), int code AND int abnormal_p)
  123. {
  124.   fflush (stdout);
  125.   fputs ("\nScheme has terminated abnormally!\n", stdout);
  126.   OS_restore_external_state ();
  127. }
  128.  
  129.  
  130. static enum syserr_names
  131. DEFUN (error_code_to_syserr, (code), int code)
  132. {
  133.   switch (code)
  134.     {
  135.     case E2BIG:        return (syserr_arg_list_too_long);
  136.     case EACCES:    return (syserr_permission_denied);
  137.     default:        return (syserr_unknown);
  138.     }
  139. }
  140.  
  141. static int
  142. DEFUN (syserr_to_error_code, (syserr), enum syserr_names syserr)
  143. {
  144.   switch (syserr)
  145.     {
  146.     case syserr_arg_list_too_long:            return (E2BIG);
  147.     case syserr_permission_denied:            return (EACCES);
  148.     default: return (0);
  149.     }
  150. }
  151.  
  152. void
  153. DEFUN (error_system_call, (code, name), int code AND enum syscall_names name)
  154. {
  155.   extern unsigned int syscall_error_code;
  156.   extern unsigned int syscall_error_name;
  157.   syscall_error_code = ((unsigned int) (error_code_to_syserr (code)));
  158.   syscall_error_name = ((unsigned int) name);
  159.   signal_error_from_primitive (ERR_IN_SYSTEM_CALL);
  160. }
  161.  
  162. CONST char *
  163. DEFUN (OS_error_code_to_message, (syserr), unsigned int syserr)
  164. {
  165.   extern char * sys_errlist [];
  166.   extern int sys_nerr;
  167.   int code = (syserr_to_error_code ((enum syserr_names) syserr));
  168.   return (((code > 0) && (code <= sys_nerr)) ? (sys_errlist [code]) : 0);
  169. }
  170.  
  171. void
  172. DEFUN (DOS_prim_check_errno, (name), enum syscall_names name)
  173. {
  174.   if (errno != EINTR)
  175.     error_system_call (errno, name);
  176.   deliver_pending_interrupts();
  177. }
  178.  
  179. void OS_restore_external_state (void)
  180. { extern void DOS_restore_interrupts(void);
  181.  
  182.   DOS_restore_interrupts();
  183.   return;
  184. }
  185.  
  186. void bcopy (const char *s1, char *s2, int n)
  187. {
  188.   while (n-- > 0)
  189.     *s2++ = *s1++;
  190.   return;
  191. }
  192.